<?php

namespace app\controller\web;

use app\service\AdminAcountService;
use app\service\AdminPathinfoService;
use app\validate\LoginValidate;

class LoginController extends WebBaseController{

    protected $beforeActionList = [
    ];

    public function initValidate(){        
        $this->validate = new LoginValidate();
    }

    public function login_action(){
        $input = $this->check("webLogin");
        $userInfo = AdminAcountService::login($input['account'],$input['password']);
        if(!isset($userInfo['vendorName'])){
            $userInfo['vendorName'] = $userInfo['vendor'];
        }
        $roleInfo = AdminPathinfoService::getRoleInfoByUser($userInfo['id'],$userInfo['level'] == 0);
        return self::ok([
            'userInfo' => $userInfo,
            'roleInfo' => $roleInfo,
        ]);
    }
}